<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Login extends CI_Controller {

    public function index() {
        if ($this->session->userdata('login_winsys') == TRUE) {
            $data['main_view'] = 'dashboard';
            $this->load->view('template', $data);
        } else {
            redirect('login/login_home', 'refresh');
        }
    }

    public function login_home() {
        $data['main_view'] = 'form_login';
        $data['form_action'] = 'login/login_process';

        $this->load->view('login_template', $data);
    }

    public function login_process() {
        $this->load->model('User_model');
        $id_user = $this->input->post('id_user');
        $password = $this->input->post('password');
        if (!($id_user && $password)) {
            redirect('login/login_home', 'refresh');
        }
        $result = $this->User_model->get_admin($id_user, $password);
        if ($result > 0) {
            $data = array(
                'login_winsys' => TRUE);
            $this->session->set_userdata($data);
            redirect('dashboard');
        } else {
            redirect('login/login_home', 'refresh');
        }
    }

    public function logout() {
        $this->session->sess_destroy();
        redirect('login/login_home', 'refresh');
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */